// elsePage/pages/pinTuanList/pinTuanList.js

Component({
  properties: {
    dataArr: {
      type: Object,
      value: () => {},
      observer: function(e) {
        let type, list, style;
        let {
          text,
          dataArr,
          stylesType
        } = e;
        if (text == "限时秒杀") {
          type = 2
        } else if (text == "拼团商品") {
          type = 1
        }
        list = dataArr;
        style = stylesType;
        this.setData({
          type,
          list,
          style,
          etime: dataArr[0].etime,
          stime: dataArr[0].stime
        })
      }
    }
  },
  data: {
    imgUrl: getApp().globalData.imgUrl,
    imgUrls: getApp().globalData.imgUrls,
    idx: 0,
    indexs: 0,
    list: []
  },
  methods: {
    choose(e) {
      let idx = e.currentTarget.dataset.idx
      if (idx != this.data.idx) {
        this.setData({
          idx,
          indexs: idx
        })
      }
    },
    checkTime() {
      let {
        etime,
        stime
      } = this.data
      if (etime - Date.now() / 1000 <= 0) {
        wx.showModal({
          title: '提示',
          content: '活动已过期',
          confirmText: '知道了',
        })
        return false
      }
      if (Date.now() / 1000 - stime <= 0) {
        wx.showModal({
          title: '提示',
          content: '活动未开始',
          confirmText: '知道了',
        })
        return false
      }
    },
    goPinTuan(e) {
      let canIUse = this.checkTime()
      if (canIUse == false) return false
      let {
        goods_id,
        limit_id,
        activity_id
      } = e.currentTarget.dataset;

      wx.navigateTo({
        url: `/pages/groupShop/groupShop?goods_id=${goods_id}&activity_id=${activity_id}`,
      })
    },
    seeMore(e) {
      let canIUse = this.checkTime()
      if (canIUse == false) return false
      let activity_id = e.currentTarget.dataset.activity_id
      wx.navigateTo({
        url: `/elsePage/pages/xianShiTeHui/xianShiTeHui?activity_id=${activity_id}&type=${this.data.type}&qtTitle=超值拼团&title=超值拼团`,
      })
    }
  }
})